﻿using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace App_Code.ErrorHandler
{
    public sealed class AjaxErrorHandlerServiceBehavior : IEndpointBehavior
    {
        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            if (endpoint == null || endpointDispatcher == null || endpointDispatcher.ChannelDispatcher == null)
                return;

            endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(new AjaxErrorHandler());
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }
    }
}